<template>
  <div class="con">
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <!-- :to="{ path: '/' }" -->
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item class="dangqian">店铺详情</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="gongsi">
        <img class="img"
             :src="detail.logo"
             alt="" />
        <div class="right">
          <div class="one">{{detail.shopName}}</div>
          <div class="two">
            <span>规模：{{detail.scale||10}}人</span>
            <span>所在地区：<span>{{detail.province}}</span><span>{{detail.city}}</span><span>{{detail.area}}</span></span>
            <span>工作日：{{detail.times}}</span>
          </div>
          <div class="swo">{{detail.intro}}</div>
          <div class="si">
            联系方式：{{detail.mobile}}
          </div>
          <div class="kefu"
               @click="kefu">客服</div>
          <div class="shou"
               @click="shoucang">
            <i :class="detail.isCollect==1 ? 'el-icon-star-on' : 'el-icon-star-off'"></i>
            <span>{{ detail.isCollect==1 ? "已收藏" : "收藏" }}</span>
          </div>
        </div>
      </div>
      <div class="right1">
        <el-tabs v-model="activeName"
                 @tab-click="handleClick">
          <el-tab-pane label="在售商品"
                       name="second"
                       class="shang">
            <div class="list">
              <div class="item"
                   v-for="(item,index) in goods"
                   :key="index"
                   @click="linkdetil(item.id)">
                <img class="img"
                     :src="item.imgurl"
                     alt="" />
                <div class="one oneline">{{item.name}}</div>
                <div class="img threeline img-add"
                     v-if="item.category==1">{{item.title}}</div>
                <div class="two">￥<span>{{item.price?item.price.toFixed(2):999.99}}</span></div>
                <div class="sw">类型: {{item.category==1?'服务类型':'普通类型'}}</div>
                <div class="si">库存{{item.stock||0}}件</div>
              </div>
            </div>
            <el-pagination background
                           layout="prev, pager, next"
                           :total="total"
                           :current-page.sync="pageNum"
                           :page-size="pageSize"
                           @current-change="handleCurrentChange"
                           prev-text="上一页"
                           next-text="下一页"
                           class="aut">
            </el-pagination>
          </el-tab-pane>
          <el-tab-pane label="需求发布"
                       name="third"
                       class="shang">
            <div class="title">
              <div class="xuqiu"
                   v-for="(item,index) in goods"
                   :key="index"
                   @click="linkxuqiu(item.id)">
                <div class="one">{{item.title}}</div>
                <div class="two">{{item.intro}}</div>
                <div class="shw">
                  <span>发布时间：{{item.caAt?item.caAt.substring(0,10):''}}</span>
                  <span>地区：{{item.city}} </span>
                  <span>状态：<span>已有{{item.count}}家领取</span> </span>
                </div>
              </div>
              <div v-if="goods.length==0"
                   style="height: 100px;line-height: 100px;text-align: center;">
                商家还没有发布需求~~~~
              </div>
            </div>
            <el-pagination background
                           layout="prev, pager, next"
                           :total="total"
                           :current-page.sync="pageNum"
                           :page-size="pageSize"
                           @current-change="handleCurrentChange"
                           prev-text="上一页"
                           next-text="下一页"
                           class="aut">
              <!-- :hide-on-single-page="true" -->
            </el-pagination>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script>
// import from ''
export default {
  name: "",
  data() {
    return {
      activeName: "second",
      id: '',
      detail: {},
      goods: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      url: ''
    };
  },
  //注册组件
  components: {},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.isinput();
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getdetail()
      this.getgoods()
    }
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() { },
  //计算属性
  computed: {},
  //方法
  methods: {
    kefu() {
      window.open(this.url)
    },
    getdetail() {
      this.$postRequest('/api/shop/getShopInfo', {
        shopId: this.id,
        userId: localStorage.getItem('userId') || -1
      }).then(res => {
        this.detail = res.data
        this.url = 'https://temp-chat.mstatik.com/widget/standalone.html?eid=' + res.data.serverId
      })
    },
    getgoods() {
      if (this.activeName == 'second') {
        this.$postRequest('/api/shop/getShopGoods', {
          shopId: this.id,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }).then(res => {
          this.goods = res.data.list
          this.total = res.data.total
        })
      } else {
        this.$postRequest('/api/shop/getShopNeed', {
          shopId: this.detail.id,
          userId: localStorage.getItem('userId') || -1,
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }).then(res => {
          this.goods = res.data.list
          this.total = res.data.total
        })
      }
    },
    share() {
      this.$message.success('复制成功')
    },
    shoucang() {
      if (localStorage.getItem('userId')) {
        this.$postRequest('/api/memberCollect/saveCollect', {
          userId: localStorage.getItem('userId'),
          status: 1,
          collectId: this.detail.id
        }).then(res => {
          this.$message.success(this.detail.isCollect == 1 ? '取消成功' : '收藏成功')
          this.getdetail()
        })
      } else {
        this.$router.push({ name: 'loginindex', params: { name: 'business' }, query: { id: this.id } })
      }
    },
    linkdetil(id) {
      this.$router.push({ name: 'detail', query: { id: id } })
    },
    linkxuqiu(id) {
      this.$router.push({ name: 'releaseitem', query: { id: id } })
    },
    isinput() {
      this.$store.commit("setDValue", true);
    },
    handleClick(tab, event) {
      this.pageNum = 1
      this.total = 0
      this.goods = []
      this.getgoods()
    },
    handleCurrentChange(currentPage) {
      this.getgoods()
    },
  }
};
</script>
<style scoped lang="scss">
.con {
  background-color: #f9f9f9;
  & > div {
    width: 1400px;
    margin: auto;
    /deep/ .el-breadcrumb {
      height: 48px;
      font-size: 14px;
      line-height: 48px;
      .el-breadcrumb__inner {
        color: #999;
        font-weight: 500;
      }
      .dangqian .el-breadcrumb__inner {
        color: #1a69e0;
      }
    }
    .gongsi {
      width: 1398px;
      height: 300px;
      background: #ffffff;
      border: 1px solid #eeeeee;
      margin-bottom: 20px;
      padding: 30px 30px 0 30px;
      display: flex;
      .img {
        width: 200px;
        height: 200px;
        margin-right: 20px;
      }
      .right {
        width: 100%;
        position: relative;
        .one {
          height: 44px;
          line-height: 44px;
          font-size: 24px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #000000;
        }
        .two {
          font-size: 16px;
          line-height: 35px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
          & > span {
            margin-right: 50px;
            & > span {
              margin-right: 8px;
            }
          }
        }
        .swo {
          margin-top: 8px;
          font-size: 16px;
          line-height: 20px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
        }
        .si {
          font-size: 16px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #000000;
          margin-top: 20px;
        }
        .kefu {
          width: 200px;
          height: 35px;
          background: rgba(1, 104, 179, 0.05);
          border: 1px solid #1a69e0;
          font-size: 16px;
          font-family: PingFang SC;
          color: #1a69e0;
          line-height: 35px;
          text-align: center;
          cursor: pointer;
          margin-top: 30px;
          &:hover {
            opacity: 0.8;
          }
        }
        .shou {
          display: flex;
          align-items: center;
          height: 18px;
          font-size: 14px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #666666;
          cursor: pointer;
          position: absolute;
          top: 0px;
          right: 0px;
          &:hover {
            color: #2f77e3;
          }
        }
        i {
          font-size: 18px;
        }
      }
    }
    .right1 {
      width: 100%;
      background: #ffffff;
      border: 1px solid #eeeeee;
      margin-bottom: 20px;
      /deep/ .el-tabs__item {
        height: 50px;
        line-height: 50px;
        padding: 0 20px;
        font-size: 18px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #999999;
        &.is-active {
          color: #409eff;
        }
      }
      /deep/ .el-tabs__nav-wrap::after {
        height: 1px;
      }
      /deep/ .el-tabs {
        background: #ffffff;
      }
      /deep/ .el-tabs__content {
        padding-bottom: 20px;
      }
      /deep/ .el-tabs__header {
        margin: 0;
      }
      .shang {
        .shangpin {
          width: 100%;
          height: 190px;
          background: #ffffff;
          border-bottom: 1px solid #eeeeee;
          display: flex;
          padding: 20px;
          .shab {
            width: 150px;
            height: 150px;
            background: #ffffff;
            border: 1px solid #f9f9f9;
            margin-right: 20px;
          }
          .right2 {
            width: 100%;
            .one {
              font-size: 16px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              color: #000000;
              margin-top: 10px;
            }
            .two {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: 500;
              color: #747474;
              margin: 18px 0;
            }
            .shw {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: bold;
              color: #e0441a;
              margin-bottom: 18px;
              span {
                font-size: 24px;
              }
            }
            .si {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: 500;
              color: #666666;
            }
          }
        }
        .xuqiu {
          width: 100%;
          background: #ffffff;
          border-bottom: 1px solid #eeeeee;
          padding: 20px;
          cursor: pointer;
          .one {
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #000000;
            margin-bottom: 10px;
          }
          .two {
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #666666;
            line-height: 20px;
            margin-bottom: 10px;
          }
          .shw {
            height: 14px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #999999;
            line-height: 20px;
            & > span {
              margin-right: 30px;
              & > span {
                color: #e0441a;
              }
            }
          }
        }
      }
      .aut {
        text-align: center;
        margin-top: 14px;
      }
      /deep/ .el-pagination button,
      .el-pagination span:not([class*='suffix']) {
        width: 60px;
      }
    }
  }
  .list {
    display: flex;
    flex-flow: row wrap;
    .item {
      width: 279.5px;
      height: 354px;
      background: #ffffff;
      border: 1px solid #eeeeee;
      border-left: 1px solid transparent;
      border-top: 1px solid transparent;
      padding: 0 20px;
      cursor: pointer;
      .img {
        width: 180px;
        height: 180px;
        display: block;
        margin: 10px auto;
      }
      .img-add {
        width: 100%;
        height: 100px;
        margin: 40px 0;
        line-height: 25px;
        display: -webkit-box;
        -webkit-line-clamp: 4;
      }
      .one {
        height: 17px;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        // line-height: 20px;
        margin: 13px 0 18px 0;
      }
      .two {
        height: 20px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #e0441a;
        line-height: 20px;
        span {
          font-size: 24px;
        }
      }
      .sw {
        height: 15px;
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #747474;
        line-height: 20px;
        margin-top: 18px;
      }
      .si {
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666666;
        margin-top: 16px;
      }
    }
  }
}
</style>
